<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"  isELIgnored="false"%>
<%  String  sourceUrl=application.getInitParameter("sourceURL");
 request.setAttribute("sourceUrl", sourceUrl);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="zh-cn">
  	<head>
	    <meta charset="utf-8">
	    <title>欢迎来到---ECHO 信息管理后台维护</title>
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	    <meta name="description" content="本管理系统主要服务于万家客户对应当前面临独生子女社会压力巨大情况">
	    <meta name="author" content="tangsixiang@163.com">
	    <!-- 需要引用的第三方css样式和js包 -->
        <jsp:include page="/topbase" />
  	</head>
  	 <body class="overflow-hidden">
		<div class="wrapper preload">
		<!-- 提出掉一部分页面rightSearch.jsp -->
		 <jsp:include page="/rightSearch" />
	 <!-- 提出掉一部分页面header.jsp  -->
	 <jsp:include page="/header" />	
	<!-- 提出掉一部分页面left.jsp  -->
	<jsp:include page="/left" />	
			<div class="main-container">
	         <!-- 我们些的功能代码都是在此部分书写 -->   
	             <div class="padding-md">
				<div class="alert alert-success alert-dismissible" role="alert">
					<button class="close" type="button" data-dismiss="alert">
						<span aria-hidden="true">×</span> <span class="sr-only">Close</span>
					</button>
					<i class="fa fa-check-circle m-right-xs"></i> <strong>你好 管理员</strong> 本页面主要维护管理员信息功能.
				</div>

				<ul class="breadcrumb">
					<li><span class="primary-font"><i class="icon-home"></i></span><a href="javascript:void();"><strong>后台权限管理</strong>--管理员维护</a></li>
				</ul>

					<table class="table table-striped" id="dataTable">
						<thead>
							<tr>
								<th>序号</th>
								<th>用户昵称</th>
								<th>登录名</th>
								<th>性别</th>
								<th>角色</th>
								<th>操心</th>
							</tr>
						</thead>
						<tbody    id="dataAjaxPages">
						
						</tbody>
					</table>
					<div id="example" style="text-align: center"> <ul id="pageLimit"></ul> </div>
					
				</div><!-- ./padding-md -->
	            
			</div><!-- /main-container -->

	<!-- 提出了foot.jsp -->
		<jsp:include page="/footer" />	
		</div><!-- /wrapper -->
	
	     <!-- 分页动态值得传递 -->
  	    <input type="hidden" id="curPage" value="1">
  	  	<input type="hidden" id="totalPage" value="3">
		
		<!-- 模态框（Modal） -->
		<div class="modal fade" id="identifier" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	    <div class="modal-dialog">
	        <div class="modal-content">
	        <div class="modal-header">
			 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" id="myModalLabel">管理员信息维护</h4>
      		 </div>
       <div class="modal-body" id="dataDongTai" >
        <!-- 动态的内容填充 -->
	      </div>  
	        <div class="modal-footer">
			<button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
			<button type="button"  onclick="saveUserRole()"  class="btn btn-warning">提交/更改</button>
			</div>
	        </div><!-- /.modal-content -->
	    </div><!-- /.modal-dialog -->
		</div>
  	</body>
  	 <script type="text/javascript">
  	 
     //页面加载完成后执行此函数
 	$(function (){
 		startUserList();
 	});
 	
	//显示打开一个模态框
	function toUpdateData(id){
		 $('#identifier').modal('show');
		   $.post("${pageContext.request.contextPath}/powerManger/selectUser",{'userId':id},
				   function(data){
				     $("#dataDongTai").empty().append(data);
			 });
	}
  
  	 	//删除数据
	function deleteData(id){
	$.confirm({
    title: '数据管理员帐号删除!',
    content:"此操作需要谨慎，管理员一单删除不可以恢复！",
    confirm: function(){
      $.post("${pageContext.request.contextPath}/powerManger/deletUser",{'userId':id},
			 function(data){
			if(data==1||data=="1"){
		     $.alert({title:"恭喜你用户删除成功！"});
		     $("#dataUser_"+id).empty();
			  }else{ $.alert({title:"对不起，本次操作失败！"});}
	         });
    } 
   });
 
	}
  	 
  	 
  	 //显示打开一个模态框
	function setUserRole(id){
		 $('#identifier').modal('show');
		   $.post("${pageContext.request.contextPath}/powerManger/selectRoleList",{'userId':id},
				   function(data){
				     $("#dataDongTai").empty().append(data);
			 });
	}
   
  	 //显示打开一个模态框
	function saveUserRole(){
	var userId=$("#userId_save").val();
	var roleId=$("#roleId_save").val();
	var roleName=$("#roleId_save ").find("option:selected").text();
		  $.post("${pageContext.request.contextPath}/powerManger/saveUserRole",{'userId':userId,'roleId':roleId},
		    function(data){
		     if(data==1||data=='1'){
		        $("#dataDongTai").empty();
			       $('#identifier').modal('hide');
			       $("#role_user_"+userId).empty().html(roleName);
			      }else{
			            $.alert({ title: '对不起，设置角色失败!',content: '请稍后再次设置!'});
			      }
			  });
	}
  
  	  
  	 var loading="<div id='loading' class='loading'>Loading pages...</div>";
  	 
	function startUserList(){
	 $("#dataAjaxPages").empty().append(loading);
		//copy 复制一份 post ajax 形式
		   $.post("${pageContext.request.contextPath}/powerManger/selectUserList",{'pageNum':1,'pageSize':10},
				   function(data){
				     $("#dataAjaxPages").empty().append(data);
				     var options = {
	                        bootstrapMajorVersion:3, //版本
	                        currentPage:$("#curPage").val(), //当前页数
	                        totalPages: $("#totalPage").val(), //总页数
	                        size:"normal",
	                        numberOfPages:3,
	                        shouldShowPage:false, 
	                        itemTexts: function (type, page, current) {
	                            switch (type) {
	                                case "first":
	                                    return "首页";
	                                case "prev":
	                                    return "上一页";
	                                case "next":
	                                    return "下一页";
	                                case "last":
	                                    return "末页";
	                                case "page":
	                                    return page;
	                            }
	                        },//点击事件，用于通过Ajax来刷新整个list列表
	                        onPageClicked: function (event, originalEvent, type, page){
	                         $.post("${pageContext.request.contextPath}/powerManger/selectUserList",{'pageNum':page,'pageSize':10},
	                          function(data){
	                            $("#dataAjaxPages").empty().append(data);
	                         });
	                        }
	                    };
	                    
	              $('#pageLimit').bootstrapPaginator(options);
			 });
		
		
		
		
		
	}
  	 
  	 </script>
</html>
